@isTest
private class TestInstagramSetup {
    static testMethod void myInstagramTest() { //Media retreive
    	Instagram_Token__c token = new Instagram_Token__c();
    	token.Access_Token__c = '1111';
    	token.Client_Id__c= '2222';
    	token.User_Id__c = '3333';
    	insert token;
    	
    	//insert media id
    	List<Instagram_Conversation__c> instaList = new List<Instagram_Conversation__c>();
    	Instagram_Conversation__c instaPost = new Instagram_Conversation__c();
    	instaList.add(instaPost);
    	
    	insert instaList;
    	
          //Test defaults
        PageReference pageRef = Page.InstagramSetup;
        Test.setCurrentPage(pageRef);
        
        //Test One - load default options
		StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
        mock.setStaticResource('staticMedia');
        mock.setStatusCode(200);
        mock.setHeader('Content-Type', 'application/json');
        Test.startTest();
        // Set the mock callout mode
        Test.setMock(HttpCalloutMock.class, mock);
        // Call the method that performs the callout
        String res = globalInstagramPost.getInfoMediaService(token.User_Id__c);	           
        globalInstagramPost.retreiveUserMediaInfo( );
        //JSON Media
        JSONMedia obj1 = new JSONMedia();
        obj1 = JSONMedia.parse(res);
        //system.debug('myjson =>' + obj1);
        //JSONMedia obj1 = JSONMedia.parse(res);

        obj1.pagination.next_url = 'https://api.instagram.com/';
              
        obj1.pagination.next_max_id = '632720081401871122_251993517';
        obj1.meta.code = 200;
        
        obj1.data[0].username = 'Munch';
        obj1.data[0].profile_picture ='http://images.ak.instagram.com/profiles/profile_615698690_75sq_1385479930.jpg';
        obj1.data[0].full_name ='Sanfora';
        obj1.data[0].images.low_resolution.url ='1';
        obj1.data[0].images.low_resolution.width =1;
        obj1.data[0].images.low_resolution.height =1;
        
        obj1.data[0].images.thumbnail.url ='1';
        obj1.data[0].images.thumbnail.width =1;
        obj1.data[0].images.thumbnail.height =1;

        obj1.data[0].images.standard_resolution.url ='1';
        obj1.data[0].images.standard_resolution.width =1;
        obj1.data[0].images.standard_resolution.height =1;
        
        
        obj1.data[0].caption.created_time ='1';
        obj1.data[0].caption.text ='Have a nice breakfast with our Muffins';
        obj1.data[0].caption.id ='1';
        
        obj1.data[0].created_time ='1';
        obj1.data[0].link = 'http://instagram.com//jH34_ONvsS/';
        obj1.data[0].comments.count = 1;
        obj1.data[0].user_has_liked = true;
        obj1.data[0].id = '632720081401871122_251993517';
        obj1.data[0].user.username = 'munchbakery';
        obj1.data[0].user.website = 'munchbakery';
        obj1.data[0].user.profile_picture = 'munchbakery';  //http://images.ak.instagram.com/profiles/profile_251993517_75sq_1360851215.jpg
        obj1.data[0].user.full_name = 'munchbakery';   //MunchBakery حلويات منش
        obj1.data[0].user.bio = 'munchbakery'; //
        obj1.data[0].user.id = 'munchbakery';   //251993517
	
        //System.assert(obj != null);
    }
    
    static testMethod void myInstagramTest2() { //Comments retreive
    	Instagram_Token__c token = new Instagram_Token__c();
    	token.Access_Token__c = '1111';
    	token.Client_Id__c= '2222';
    	token.User_Id__c = '3333';
    	insert token;
    	
    	//insert media id
    	List<Instagram_Conversation__c> instaList = new List<Instagram_Conversation__c>();
    	Instagram_Conversation__c instaPost = new Instagram_Conversation__c();
    	instaPost.Media_ID__c ='632720081401871122_251993517';
    	instaList.add(instaPost);
    	
    	insert instaList;
    	
          //Test defaults
        PageReference pageRef = Page.InstagramSetup;
        Test.setCurrentPage(pageRef);
        
        //Test One - load default options
		StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
        mock.setStaticResource('staticMediaComment');
        mock.setStatusCode(200);
        mock.setHeader('Content-Type', 'application/json');
        Test.startTest();
        // Set the mock callout mode
        Test.setMock(HttpCalloutMock.class, mock);
        // Call the method that performs the callout
        //globalInstagramPost.postSchedServiceRequest(); 
		datetime dt = datetime.now();
        //String formatedDt = dt.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');//format the datetime to make it Dynamic Soql ready
        Instagram_Conversation__c instaMediaList = [Select Id, Media_Id__c From Instagram_Conversation__c where Media_Id__c =:instaPost.Media_ID__c];           

		//make the call out  
		String res = globalInstagramPost.getCommentService(instaMediaList.media_id__c, token.Access_Token__c);
		globalInstagramPost.postSchedCommentServiceRequest(instaMediaList.media_id__c, token.Access_Token__c); 
		

        //JSON Media
        String userData = res;        
        userData = userData.replace('"from":', '"from_user":');        
		JSONMediaComments obj1 = JSONMediaComments.parse(userData);
		obj1.meta.code = 200;
        
        obj1.data[0].created_time = 'Munch';
		obj1.data[0].text = 'Munch';
		obj1.data[0].from_user.username = 'Munch';
		obj1.data[0].from_user.profile_picture = 'pic';
		obj1.data[0].from_user.id = '1';
		obj1.data[0].from_user.full_name = 'Munch';
		obj1.data[0].id = 'Munch';
		
        //System.assert(obj != null);
    }   
    
    static testMethod void myInstagramTestLikes() { //Comments retreive
    	Instagram_Token__c token = new Instagram_Token__c();
    	token.Access_Token__c = '1111';
    	token.Client_Id__c= '2222';
    	token.User_Id__c = '3333';
    	insert token;
    	
    	//insert media id
    	List<Instagram_Conversation__c> instaList = new List<Instagram_Conversation__c>();
    	Instagram_Conversation__c instaPost = new Instagram_Conversation__c();
    	instaPost.Media_ID__c ='632720081401871122_251993517';
    	instaList.add(instaPost);
    	
    	insert instaList;
    	
          //Test defaults
        PageReference pageRef = Page.InstagramSetup;
        Test.setCurrentPage(pageRef);
        
        //Test One - load default options
		StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
        mock.setStaticResource('staticMediaLike');
        mock.setStatusCode(200);
        mock.setHeader('Content-Type', 'application/json');
        Test.startTest();
        // Set the mock callout mode
        Test.setMock(HttpCalloutMock.class, mock);
        // Call the method that performs the callout
        //globalInstagramPost.postSchedServiceRequest(); 
		datetime dt = datetime.now();
        //String formatedDt = dt.format('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'');//format the datetime to make it Dynamic Soql ready
        Instagram_Conversation__c instaMediaList = [Select Id, Media_Id__c From Instagram_Conversation__c where Media_Id__c =:instaPost.Media_ID__c];           

		//make the call out  
		String res = globalInstagramPost.getLikeService(instaMediaList.media_id__c, token.Access_Token__c);
		globalInstagramPost.postSchedLikeServiceRequest(instaMediaList.media_id__c, token.Access_Token__c); 
		

        //JSON Media
        String userData = res;        
		JSONMediaLikes obj1 = JSONMediaLikes.parse(userData);
		obj1.meta.code = 200; 
         
		obj1.data[0].bio = 'Munch';
		obj1.data[0].username = 'Munch';
		obj1.data[0].profile_picture = 'pic';
		obj1.data[0].id = '1';
		obj1.data[0].full_name = 'Munch';
		
        //System.assert(obj != null);
    }       


static testMethod void myInstagramTest3() { //Test InstagramSetup page
    	Instagram_Token__c token = new Instagram_Token__c();
    	token.Access_Token__c = '1111';
    	token.Client_Id__c= '2222';
    	token.User_Id__c = '3333';
    	insert token;
    	
    	//insert media id
    	List<Instagram_Conversation__c> instaList = new List<Instagram_Conversation__c>();
    	Instagram_Conversation__c instaPost = new Instagram_Conversation__c();
    	instaList.add(instaPost);
    	
    	insert instaList;
    	
    	
          //Test defaults
        PageReference pageRef = Page.InstagramSetup;
        Test.setCurrentPage(pageRef);
        
        //Test One - load default options
        InstagramSetup controller = new InstagramSetup();
        controller.retreiveUserMedia();
        controller.scheduleDemoSingleMediaComments();

    }    

static testMethod void myInstagramTestSetupLikes() { //Test InstagramSetup page
    	Instagram_Token__c token = new Instagram_Token__c();
    	token.Access_Token__c = '1111';
    	token.Client_Id__c= '2222';
    	token.User_Id__c = '3333';
    	insert token;
    	
    	//insert media id
    	List<Instagram_Conversation__c> instaList = new List<Instagram_Conversation__c>();
    	Instagram_Conversation__c instaPost = new Instagram_Conversation__c();
    	instaList.add(instaPost);
    	
    	insert instaList;
    	
    	
          //Test defaults
        PageReference pageRef = Page.InstagramSetup;
        Test.setCurrentPage(pageRef);
        
        //Test One - load default options
        InstagramSetup controller = new InstagramSetup();
        controller.retreiveUserMedia();
        controller.scheduleDemoSingleMediaLike();

    } 
static testMethod void myInstagramBatchComments() {
    	Instagram_Token__c token = new Instagram_Token__c();
    	token.Access_Token__c = '1111';
    	token.Client_Id__c= '2222';
    	token.User_Id__c = '3333';
    	insert token;
    	
    	//insert media id
    	List<Instagram_Conversation__c> instaList = new List<Instagram_Conversation__c>();
    	Instagram_Conversation__c instaPost = new Instagram_Conversation__c();
    	instaPost.Media_ID__c ='632720081401871122_251993517';
    	instaList.add(instaPost);
    	
    	insert instaList;
    	
        batchInstagramComments b = new batchInstagramComments();
        Database.executeBatch(b,1);
		
        //System.assert(obj != null);
    }   

static testMethod void myInstagramBatchLikes() {
    	Instagram_Token__c token = new Instagram_Token__c();
    	token.Access_Token__c = '1111';
    	token.Client_Id__c= '2222';
    	token.User_Id__c = '3333';
    	insert token;
    	
    	//insert media id
    	List<Instagram_Conversation__c> instaList = new List<Instagram_Conversation__c>();
    	Instagram_Conversation__c instaPost = new Instagram_Conversation__c();
    	instaPost.Media_ID__c ='632720081401871122_251993517';
    	instaList.add(instaPost);
    	
    	insert instaList;
    	
        batchInstagramLikes b = new batchInstagramLikes();
        Database.executeBatch(b,1);
		
        //System.assert(obj != null);
    }  
    
static testMethod void myInstagramScheduleComments() {
    	Instagram_Token__c token = new Instagram_Token__c();
    	token.Access_Token__c = '1111';
    	token.Client_Id__c= '2222';
    	token.User_Id__c = '3333';
    	insert token;
    	
    	//insert media id
    	List<Instagram_Conversation__c> instaList = new List<Instagram_Conversation__c>();
    	Instagram_Conversation__c instaPost = new Instagram_Conversation__c();
    	instaPost.Media_ID__c ='632720081401871122_251993517';
    	instaList.add(instaPost);
    	
    	insert instaList;	
      Test.startTest();
      // Schedule the test job
      SchedulableInstagramComments.startComments();
      Test.stopTest();
                        
	}

static testMethod void myInstagramScheduleLikes() {
    	Instagram_Token__c token = new Instagram_Token__c();
    	token.Access_Token__c = '1111';
    	token.Client_Id__c= '2222';
    	token.User_Id__c = '3333';
    	insert token;
    	
    	//insert media id
    	List<Instagram_Conversation__c> instaList = new List<Instagram_Conversation__c>();
    	Instagram_Conversation__c instaPost = new Instagram_Conversation__c();
    	instaPost.Media_ID__c ='632720081401871122_251993517';
    	instaList.add(instaPost);
    	
    	insert instaList;	
      Test.startTest();
      // Schedule the test job
      SchedulableInstagramLikes.startLikes();
      Test.stopTest();
                        
	}
	
static testMethod void myInstagramSchedulePost() {
    	Instagram_Token__c token = new Instagram_Token__c();
    	token.Access_Token__c = '1111';
    	token.Client_Id__c= '2222';
    	token.User_Id__c = '3333';
    	insert token;
    	
    	//insert media id
    	List<Instagram_Conversation__c> instaList = new List<Instagram_Conversation__c>();
    	Instagram_Conversation__c instaPost = new Instagram_Conversation__c();
    	instaList.add(instaPost);
    	
    	insert instaList;	   
      Test.startTest();
      // Schedule the test job
       SchedulableInstagramPost.startPost();
      Test.stopTest();
                        
	}	
}